package com.dly.hope.constant;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author linyu.dai
 * @project myserve
 * @description 统一返回的实体类
 * @creat 2022/8/26 14:50:49
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private String code;

    private String message;

    private T date;

    public static <T> R<T> ok(String message) {
        return new R<T>(HttpConstant.success, message, null);
    }

    public static<T> R<T> error(String code,String message) {
        return new R<T>(code, message, null);
    }

    public static <T> R<T> ok(T date, String message) {
        return new R<T>(HttpConstant.success, message, date);
    }

    public static<T> R<T> error(GlobalException e){
        return new R<>(e.getCode(), e.getMessage(), null);
    }
}
